(function() {
  app.controller('payCtrl', function($scope, tradeApi, $sce, $timeout) {
    $scope.init = function() {
      tradeApi
        .query({
          funcId: '300006',
          data: {}
        })
        .then(function(banks) {
          $scope.banks = banks || [];
        });
    };
    $scope.pay = function() {
      var path = location.pathname.substring(0, window.location.pathname.lastIndexOf('/') + 1);
      tradeApi.query({
        funcId: '300012',
        data: {
          request_channel: '3',
          occur_balance: $scope.occur_balance,
          bank_no: $scope.bank_no,
          success_url: location.origin + path + 'api/900001'
        }
      }).then(function(res) {
        $scope.form = {
          req_data: JSON.stringify(res.form)
        };
        $scope.url = $sce.trustAsResourceUrl(res.to_url);
        $timeout(function() {
          document.getElementById('myForm').submit();
        }, 0);
      });
    };
  });
})();